system: add logging wrappers for basic system functions
authorFelix Fietkau <[email protected]>
Tue, 30 Sep 2025 12:06:08 +0000 (14:06 +0200)
committerFelix Fietkau <[email protected]>
Tue, 30 Sep 2025 12:06:30 +0000 (14:06 +0200)
Helps with debugging by providing context for the calls

Signed-off-by: Felix Fietkau <[email protected]>
system-dummy.c
system-linux.c
system-log.h [new file with mode: 0644]
system.c
system.h

index 59411c4df2b6d4a492ee5c4c49b5943710a5c63c..ea2f865e33cee89f1e80879daf2118d391b26e3a 100644 (file)
@@ -11,6 +11,7 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  */
+#define SYSTEM_IMPL
 #include <sys/time.h>
 #include <stdio.h>
 #include <string.h>
@@ -32,37 +33,26 @@ int system_init(void)
 
 int system_bridge_addbr(struct device *bridge, struct bridge_config *cfg)
 {
-       D(SYSTEM, "brctl addbr %s vlan_filtering=%d",
-         bridge->ifname, cfg->vlan_filtering);
        return 0;
 }
 
 int system_bridge_delbr(struct device *bridge)
 {
-       D(SYSTEM, "brctl delbr %s", bridge->ifname);
        return 0;
 }
 
 int system_bridge_addif(struct device *bridge, struct device *dev)
 {
-       D(SYSTEM, "brctl addif %s %s", bridge->ifname, dev->ifname);
        return 0;
 }
 
 int system_bridge_delif(struct device *bridge, struct device *dev)
 {
-       D(SYSTEM, "brctl delif %s %s", bridge->ifname, dev->ifname);
        return 0;
 }
 
 int system_bridge_vlan(const char *iface, uint16_t vid, int16_t vid_end, bool add, unsigned int vflags)
 {
-       D(SYSTEM, "brctl vlan %s %s %s vid=%d vid_end=%d pvid=%d untag=%d",
-         add ? "add" : "remove",
-         (vflags & BRVLAN_F_SELF) ? "self" : "master",
-         iface, vid, vid_end,
-         !!(vflags & BRVLAN_F_PVID),
-         !!(vflags & BRVLAN_F_UNTAGGED));
        return 0;
 }
 
index 2303cba4ab13da80c4fc15dec0ad9fab6dfbca06..65825352f9b08f43d165dba650bfa7c7fbb1e42a 100644 (file)
@@ -17,6 +17,7 @@
  * GNU General Public License for more details.
  */
 #define _GNU_SOURCE
+#define SYSTEM_IMPL
 
 #include <sys/socket.h>
 #include <sys/ioctl.h>
diff --git a/system-log.h b/system-log.h
new file mode 100644 (file)
index 0000000..f3fed7e
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * netifd - network interface daemon
+ * Copyright (C) 2025 Felix Fietkau <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+#ifndef __NETIFD_SYSTEM_LOG_H
+#define __NETIFD_SYSTEM_LOG_H
+
+
+#define system_if_up(dev) ({ \
+       struct device *_dev = dev;                                      \
+       D(SYSTEM, "system_if_up(%s)", _dev ? _dev->ifname : "<none>");  \
+       system_if_up(_dev);                                             \
+})
+
+#define system_if_down(dev) ({ \
+       struct device *_dev = dev;                                      \
+       D(SYSTEM, "system_if_down(%s)", _dev ? _dev->ifname : "<none>");        \
+       system_if_down(_dev);                                           \
+})
+
+#define system_bridge_addbr(bridge, cfg) ({ \
+       struct device *_bridge = bridge;                                        \
+       struct bridge_config *_cfg = cfg;                                       \
+       D(SYSTEM, "system_bridge_addbr(%s)", _bridge ? _bridge->ifname : "<none>");     \
+       system_bridge_addbr(_bridge, _cfg);                                     \
+})
+
+#define system_bridge_delbr(bridge) ({ \
+       struct device *_bridge = bridge;                                        \
+       D(SYSTEM, "system_bridge_delbr(%s)", _bridge ? _bridge->ifname : "<none>");     \
+       system_bridge_delbr(_bridge);                                           \
+})
+
+#define system_bridge_addif(bridge, dev) ({ \
+       struct device *_bridge = bridge;                                        \
+       struct device *_dev = dev;                                              \
+       D(SYSTEM, "system_bridge_addif(%s, %s)", _bridge ? _bridge->ifname : "<none>", _dev ? _dev->ifname : "<none>"); \
+       system_bridge_addif(_bridge, _dev);                                     \
+})
+
+#define system_bridge_delif(bridge, dev) ({ \
+       struct device *_bridge = bridge;                                        \
+       struct device *_dev = dev;                                              \
+       D(SYSTEM, "system_bridge_delif(%s, %s)", _bridge ? _bridge->ifname : "<none>", _dev ? _dev->ifname : "<none>"); \
+       system_bridge_delif(_bridge, _dev);                                     \
+})
+
+#define system_bridge_vlan(iface, vid, vid_end, add, vflags) ({ \
+       const char *_iface = iface;                                             \
+       uint16_t _vid = vid;                                                    \
+       int16_t _vid_end = vid_end;                                             \
+       bool _add = add;                                                        \
+       unsigned int _vflags = vflags;                                          \
+       D(SYSTEM, "system_bridge_vlan(%s, %s, %s, vid=%d, vid_end=%d, pvid=%d, untag=%d)", \
+         _iface ? _iface : "<none>",                                           \
+         _add ? "add" : "remove",                                              \
+         (_vflags & BRVLAN_F_SELF) ? "self" : "master",                        \
+         _vid, _vid_end,                                                       \
+         !!(_vflags & BRVLAN_F_PVID),                                          \
+         !!(_vflags & BRVLAN_F_UNTAGGED));                                     \
+       system_bridge_vlan(_iface, _vid, _vid_end, _add, _vflags);              \
+})
+
+#endif
index 32597c14e29145a5187d0642769f6eb5e9458aa7..a9a54394ad8a9923be5e39a3d9e5abc61fe0e63c 100644 (file)
--- a/system.c
+++ b/system.c
@@ -11,6 +11,7 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  */
+#define SYSTEM_IMPL
 #include "netifd.h"
 #include "system.h"
 #include <fcntl.h>
index 084ca969108839cf34253f77eb9991a685b19ee8..e8edfb77aeb2149de8e43fb392560be0d5b7d02b 100644 (file)
--- a/system.h
+++ b/system.h
@@ -324,4 +324,8 @@ int system_link_netns_move(struct device *dev, const pid_t target_ns, const char
 int system_netns_open(const pid_t target_ns);
 int system_netns_set(int netns_fd);
 
+#ifndef SYSTEM_IMPL
+#include "system-log.h"
+#endif
+
 #endif